<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">

<h:body>

	<ui:composition template="/WEB-INF/templates/1000_layout.xhtml">

		<ui:define name="head">
			<title>Purchase Order</title>
		</ui:define>

		<ui:define name="user_project_list_show">
			<ui:param name="showUserProjectlist" value="false" />
		</ui:define>

		<ui:define name="content">

			<br />
			<p:fieldset id="fsMain" style="background-color:#F5FFF5;">
				<h:form id="frmHeader">
					<table border="0" style="width: 100%;">
						<tr>
							<td style="width: 60%;" rowspan="2"></td>
							<td colspan="2"><h1>PURCHASE ORDER</h1></td>
						</tr>
						<tr>
							<td style="width: 20%"><p:panelGrid style="width: 100%;">
									<f:facet name="header">
										<p:row>
											<p:column>
												<h:outputText value="DATE" />
											</p:column>
										</p:row>
									</f:facet>
									<p:row
										rendered="#{not empty dtPurchaseOrderEditView.purchaseOrder.orderDate}">
										<p:column>
											<h:outputText
												value="#{dtPurchaseOrderEditView.purchaseOrder.orderDate}">
												<f:convertDateTime pattern="MM/dd/yyyy" />
											</h:outputText>
										</p:column>
									</p:row>
									<p:row
										rendered="#{empty dtPurchaseOrderEditView.purchaseOrder.orderDate}">
										<p:column>
											<h:outputText value="&nbsp;" />
										</p:column>
									</p:row>
								</p:panelGrid></td>
							<td style="width: 20%"><p:panelGrid style="width: 100%;">
									<f:facet name="header">
										<p:row>
											<p:column>
												<h:outputText value="P.O. NUMBER" />
											</p:column>
										</p:row>
									</f:facet>
									<p:row>
										<p:column>
											<h:outputText style="font-style:italic;"
												rendered="#{empty dtPurchaseOrderEditView.purchaseOrder.poNumber}"
												value="Not available in #{dtPurchaseOrderEditView.purchaseOrder.status} status" />
											<h:outputText
												value="#{dtPurchaseOrderEditView.purchaseOrder.poNumber}" />
										</p:column>
									</p:row>
								</p:panelGrid></td>
						</tr>
					</table>
					<br />
					<table border="0" style="width: 100%">
						<tr>
							<td style="width: 50%; vertical-align: top;"><p:panelGrid
									style="width: 100%;">
									<f:facet name="header">
										<p:row>
											<p:column style="padding-right:5px;">
												<h:outputText value="VENDOR" />
											</p:column>
										</p:row>
									</f:facet>
									<p:row>
										<p:column>
											<h:outputText
												value="#{dtPurchaseOrderEditView.purchaseOrder.supplier.name}" />
											<br />
											<h:outputText
												value="#{dtPurchaseOrderEditView.purchaseOrder.supplier.address}" />
											<br />
											<h:outputText
												value="ATTN: #{dtPurchaseOrderEditView.purchaseOrder.supplier.address.contactPerson}" />
										</p:column>
									</p:row>
								</p:panelGrid></td>
							<td style="width: 50%; vertical-align: top;"><p:panelGrid
									style="width: 100%;">
									<f:facet name="header">
										<p:row>
											<p:column style="padding-right:5px;">
												<h:outputText value="SHIP TO" />
											</p:column>
										</p:row>
									</f:facet>
									<p:row rendered="#{dtPurchaseOrderEditView.editable}">
										<p:column>
											<p:selectOneMenu value="#{dtPurchaseOrderEditView.warehouse}">
												<p:ajax event="change" update=":frmSave"
													listener="#{dtPurchaseOrderEditView.markDirty}" />
												<f:selectItems var="warehouse"
													value="#{dtPurchaseOrderEditView.warehouses}"
													itemLabel="#{warehouse.name}" itemValue="#{warehouse.id}" />
											</p:selectOneMenu>
										</p:column>
									</p:row>
									<p:row rendered="#{not dtPurchaseOrderEditView.editable}">
										<p:column>
											<h:outputText
												value="#{dtPurchaseOrderEditView.purchaseOrder.warehouse.name}" />
											<br />
											<h:outputText
												value="#{dtPurchaseOrderEditView.purchaseOrder.warehouse.address}" />
											<br />
											<h:outputText
												value="ATTN: #{dtPurchaseOrderEditView.purchaseOrder.warehouse.address.contactPerson}" />
										</p:column>
									</p:row>
								</p:panelGrid></td>
						</tr>
					</table>
					<br />

					<table border="0" style="width: 100%">
						<tr>
							<td style="width: 25%;"><p:panelGrid style="width: 100%;">
									<f:facet name="header">
										<p:row>
											<p:column>
												<h:outputText value="PURCHASER" />
											</p:column>
										</p:row>
									</f:facet>
									<p:row>
										<p:column>
											<h:outputText
												value="#{dtPurchaseOrderEditView.purchaseOrder.owner.displayName}" />
										</p:column>
									</p:row>
								</p:panelGrid></td>
							<td style="width: 25%;"><p:panelGrid style="width: 100%;">
									<f:facet name="header">
										<p:row>
											<p:column>
												<h:outputText value="TERMS" />
											</p:column>
										</p:row>
									</f:facet>
									<p:row>
										<p:column>
											<p:inputText rendered="#{dtPurchaseOrderEditView.editable}"
												id="term" value="#{dtPurchaseOrderEditView.term}"
												required="true" requiredMessage="Please enter term">
												<p:ajax event="keyup" update=":frmSave"
													listener="#{dtPurchaseOrderEditView.markDirty}" />
											</p:inputText>
											<h:outputText
												rendered="#{not dtPurchaseOrderEditView.editable}"
												value="#{dtPurchaseOrderEditView.term}" />
											<br />
											<p:message for="term" />
										</p:column>
									</p:row>
								</p:panelGrid></td>
							<td style="width: 25%;"><p:panelGrid style="width: 100%;">
									<f:facet name="header">
										<p:row>
											<p:column>
												<h:outputText value="P.R. NUMBER" />
											</p:column>
										</p:row>
									</f:facet>
									<p:row>
										<p:column>
											<h:outputText
												value="#{dtPurchaseOrderEditView.purchaseOrder.purchaseRequisition.prNumber}" />
										</p:column>
									</p:row>
								</p:panelGrid></td>
							<td style="width: 25%;"><p:panelGrid style="width: 100%;">
									<f:facet name="header">
										<p:row>
											<p:column>
												<h:outputText value="DUE DATE" />
											</p:column>
										</p:row>
									</f:facet>
									<p:row>
										<p:column>
											<p:calendar id="dueDate"
												rendered="#{dtPurchaseOrderEditView.editable}"
												value="#{dtPurchaseOrderEditView.dueDate}" showOn="button"
												required="true" requiredMessage="Due date is mandatory!" />
											<h:outputText
												rendered="#{not dtPurchaseOrderEditView.editable}"
												value="#{dtPurchaseOrderEditView.dueDate}">
												<f:convertDateTime pattern="MM/dd/yyyy" />
											</h:outputText>
											<br />
											<p:message for="dueDate" />
										</p:column>
									</p:row>
								</p:panelGrid></td>
						</tr>
					</table>
					<br />
					<h:outputText
						value="Please supply the following items according to our general purchase conditions." />
					<br />


					<p:remoteCommand name="rcSave" update=":fsMain"
						action="#{dtPurchaseOrderEditView.save}" />
					<p:remoteCommand name="rcSubmit" update=":fsMain"
						action="#{dtPurchaseOrderEditView.saveAndSubmit}" />
					<p:remoteCommand name="rcReopen" update=":fsMain"
						action="#{dtPurchaseOrderEditView.reopen}" />
					<p:remoteCommand name="rcApprove" update=":fsMain"
						action="#{dtPurchaseOrderEditView.approve}" />
					<p:remoteCommand name="rcAcknowledge" update=":fsMain"
						action="#{dtPurchaseOrderEditView.acknowledge}" />
					<p:remoteCommand name="rcReceive" update=":fsMain"
						action="#{dtPurchaseOrderEditView.receive}" />
					<p:remoteCommand name="rcWithdraw" update=":fsMain"
						action="#{dtPurchaseOrderEditView.withdraw}" />
					<p:remoteCommand name="rcClose" update=":fsMain"
						action="#{dtPurchaseOrderEditView.complete}" />

				</h:form>

				<br />
				<h:form>
					<ui:include
						src="/WEB-INF/templates/entity/purchaseOrder.items.xhtml">
						<ui:param name="bean" value="#{dtPurchaseOrderItemsView}" />
						<ui:param name="deleteUpdate" value=":fsMain :frmSave" />
						<ui:param name="backingBean" value="#{dtPurchaseOrderItemsView}" />
						<ui:param name="readonly"
							value="#{not dtPurchaseOrderEditView.editable}" />
					</ui:include>
				</h:form>
				<br />
				<p:fieldset legend="Adjustments">

					<h:form id="adjustmentForm">
						<p:dataTable var="adjustment" style="width:100%"
							value="#{dtPurchaseOrderAdjustmetView.adjustments}">
							<p:column headerText="Item #" style="width:10%">
								<h:outputText value="#{adjustment.itemNumber}" />
							</p:column>
							<p:column headerText="Description" style="width:60%">
								<h:outputText value="#{adjustment.description}" />
							</p:column>
							<p:column headerText="Sub-Total"
								style="text-align: right;width:20%;">
								<h:outputText value="#{adjustment.amount}">
									<f:convertNumber currencySymbol="" type="currency" />
								</h:outputText>
							</p:column>
							<p:column headerText="Delete"
								style="text-align: center;width:10%;"
								rendered="#{dtPurchaseOrderEditView.editable}">
								<p:commandButton value="Delete" update=":adjustmentForm :fsMain"
									action="#{dtPurchaseOrderAdjustmetView.delete(adjustment.id)}" />
							</p:column>
						</p:dataTable>
					</h:form>
					<h:form>
						<br />
						<p:panelGrid rendered="#{dtPurchaseOrderEditView.editable}">
							<f:facet name="header">
								<p:row>
									<p:column>
										<h:outputText value="Description" />
									</p:column>
									<p:column>
										<h:outputText value="Amount" />
									</p:column>
									<p:column>
										<h:outputText value="Action" />
									</p:column>
								</p:row>
							</f:facet>
							<p:row>
								<p:column>
									<h:inputText id="description" size="50" required="true"
										requiredMessage="Please enter description"
										value="#{dtPurchaseOrderAdjustmetView.description}" />
									<br />
									<h:message for="description" />
								</p:column>
								<p:column>
									<h:inputText id="amount"
										value="#{dtPurchaseOrderAdjustmetView.amount}" />
									<br />
									<h:message for="amount" />
								</p:column>
								<p:column>
									<p:commandButton value="Add Adjustment" update="@form :fsMain"
										action="#{dtPurchaseOrderAdjustmetView.add}" />
								</p:column>
							</p:row>
						</p:panelGrid>
					</h:form>
				</p:fieldset>

				<br />
				<h:form id="totalForm">

					<p:panelGrid style="width: 100%;">
						<p:row>
							<p:column styleClass="ui-widget-header"
								style="width:90%;text-align: right">
								<h:outputText value="TOTAL &nbsp;" />
							</p:column>
							<p:column style="width:10%;text-align: center;">
								<strong> <h:outputText
										value="#{dtPurchaseOrderEditView.total}">
										<f:convertNumber currencySymbol="PHP " type="currency" />
									</h:outputText>
								</strong>
							</p:column>
						</p:row>
					</p:panelGrid>

				</h:form>

				<br />

				<h:form id="pORemarksForm">

					<p:panelGrid style="width: 100%;">
						<f:facet name="header">
							<p:row>
								<p:column>
									<h:outputText value="Remarks" />
								</p:column>
							</p:row>
						</f:facet>
						<p:row rendered="#{not dtPurchaseOrderEditView.editable}">
							<p:column>
								<pre>
									<h:outputText value="#{dtPurchaseOrderEditView.remarks}" />
								</pre>
							</p:column>
						</p:row>
						<p:row rendered="#{dtPurchaseOrderEditView.editable}">
							<p:column>
								<p:inputTextarea value="#{dtPurchaseOrderEditView.remarks}"
									style="resize:vertical;width: 100%" rows="3" counter="display"
									maxlength="1024" counterTemplate="{0} characters remaining.">
									<p:ajax event="keyup" update=":frmSave"
										listener="#{dtPurchaseOrderEditView.markDirty}" />
								</p:inputTextarea>
								<br />
								<h:outputText id="display" />
							</p:column>
						</p:row>
					</p:panelGrid>
				</h:form>
				<br />
				<h:outputText value="TERMS AND CONDITIONS" />
				<ol>
					<li>Acceptance is subject to ECOWORK INC. quality check and
						inspection.</li>
					<li>Goods delivered not in accordance with specificatins will
						be returned and should be replaced within ___ days, unless
						instructed not to do so.</li>
					<li>Goods and Services must be accompanied by the original
						Purchase Order and a Copy of Sales Invoice or O.R. respectively.</li>
					<li>Delivery schedule must be strictly followed. Failure to
						comply with the above schedule shall be sufficient ground to
						ECOWORK INC. to cancel part or entire order or to impose a penalty
						of 1/10 or 1% of contract price for each day of delay.</li>
					<li>All Statement of Account shall be submitted to our
						accounting section every 15th and 30th of the month.</li>
					<li>Release of BIR Form 2307 is upon receipt of Sales Invoice
						/ O.R. from the supplier.</li>
					<li>Unless we receive your acknowledgement witin 2 days, we
						will consider the general conditions of this order duly accpeted
						and confirmed.</li>
				</ol>
				<h:outputText
					value="All invoices and shipping documents to be addressed and consigned to ECOWORK INC." />
				<br />
				<table border="0" style="width: 100%">
					<tr>
						<td style="width: 50%;">
							<div style="width: 95%; border: 1px solid black; padding: 10px;">
								<h:outputText value="Approved by:" />
								<br /> <br /> 
											<h:outputText
												value="#{dtPurchaseOrderEditView.purchaseOrder.approvedBy.displayName}" /><br />
								<hr />
								<br />
							</div>
						</td>
						<td style="width: 50%;">
							<div style="width: 95%; border: 1px solid black; padding: 10px;">
								<h:outputText value="Accepted/Confirmed by:" />
								<br /> <br /> <br />
								<hr />
								<br />
							</div>
						</td>
					</tr>
				</table>

				<br />
				<h:form id="frmSave">
					<p:commandButton id="save" value="Save" type="button"
						onclick="rcSave()" rendered="#{dtPurchaseOrderEditView.editable}"
						disabled="#{not dtPurchaseOrderEditView.dirty}" />
					<p:commandButton id="submit" value="Submit" type="button"
						onclick="rcSubmit()"
						rendered="#{dtPurchaseOrderEditView.showSubmit}" />
					<p:commandButton id="reopen" value="Reopen" type="button"
						onclick="rcReopen()"
						rendered="#{dtPurchaseOrderEditView.showReopen}" />
					<p:commandButton id="approve" value="Approve" type="button"
						onclick="rcApprove()"
						rendered="#{dtPurchaseOrderEditView.showApprove}" />
					<p:commandButton id="acknowledge" value="Supplier Acknowledged"
						type="button" onclick="rcAcknowledge()"
						rendered="#{dtPurchaseOrderEditView.showAcknowledge}" />
					<p:commandButton id="received" value="Receive..." type="button"
						onclick="rcReceived()"
						rendered="#{dtPurchaseOrderEditView.showReceived}" />
					<p:commandButton id="withdraw" value="Request Withdrawal"
						type="button" onclick="rcWithdraw()"
						rendered="#{dtPurchaseOrderEditView.showWithdraw}" />
					<p:commandButton id="close" value="Close" type="button"
						onclick="rcClose()"
						rendered="#{dtPurchaseOrderEditView.showClose}" />

					<p:commandButton immediate="true" value="Open PR"
						action="#{dtPurchaseOrderEditView.loadMain}" ajax="false" />
					<p:commandButton value="Print" ajax="false"
						action="#{dtPurchaseOrderEditView.printPdf}" />
				</h:form>
			</p:fieldset>

		</ui:define>

	</ui:composition>
</h:body>
</html>